/**
 * 跨域演示服务接口
 * @module server
 * @author its-wild
 * @date 2021/04/16
 */

const express = require('express')
const app = express()
const port = 9527


//设置跨域访问
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();

})

// 接口地址为 http://localhost:9527/getData 
app.get('/getData', (req, res) => {
    let tmpData = {
        code: 200,
        msg: '成功',
        data: '这是后台返回的数据！'
    }
    res.send(tmpData)
})

const server = app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})
